<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
    <!--<link rel="stylesheet" href="media/css/dataTables.bootstrap.min.css">
    <script src="media/js/jquery.dataTables.min.js"/>
    <script src="media/js/dataTables.bootstrap.min.js"/>-->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">首页</a>
            <a href="">用户管理</a>
            <a>
              <cite>用户列表</cite></a>
          </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5">
                        <div class="layui-inline layui-show-xs-block">
                            <input class="layui-input" autocomplete="off" placeholder="请输入用户名"  id="SearchUsername">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input class="layui-input" autocomplete="off" placeholder="请输入手机号"  id="SearchPhone">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text"  placeholder="请输入邮箱号" autocomplete="off" id="SearchEmail"
                                   class="layui-input">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn" lay-filter="sreach" onclick="init(1)"><i class="layui-icon">&#xe615;</i></button>
                        </div>
                    </form>
                </div>
                <div class="layui-card-header">
                    <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除
                    </button>
                </div>
                <div class="layui-card-body layui-table-body layui-table-main">
                    <table class="layui-table layui-form">
                        <thead>
                        <tr>
                            <th>
                                <input type="checkbox" lay-filter="checkall" class="checkbox" lay-skin="primary">
                            </th>
                            <th>用户名</th>
                            <th>性别</th>
                            <th>身份证号</th>
                            <th>银行卡号</th>
                            <th>手机号</th>
                            <th>邮箱号码</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody id="UserList">
                        </tbody>
                    </table>
                </div>
                <div class="layui-card-body ">
                    <div class="page">
                        <div id="page1">

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    var UserId;
    init(1);
    function init(current) {
         // alert($("#SearchUsername").val()+":"+$("#SearchPhone").val()+":"+$("#SearchEmail").val());
        $("#UserList").empty("");
        $("#page1").empty("");
        $.ajax({
            type: 'POST',
            url: "ListUser",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            data:JSON.stringify({
                "currentPage":current,
                "username":$("#SearchUsername").val(),
                "phone":$("#SearchPhone").val(),
                "email":$("#SearchEmail").val(),
            }),
            success: function (data) {
                UserId = data.id;
                var UserInfoList = "";
                $(data.list).each(function (index, item) {
                    UserInfoList = "<tr id='userinfomation'>\n" +
                        "<td>\n" +
                        "  <input type=\"checkbox\" name=\"id\" value=\"1\"   lay-skin=\"primary\" id=" + item.id + " class=\"checkbox1\">\n" +
                        "</td>\n" +
                        "<td>" + item.username + "</td>\n";
                    if (item.gender == 1) {
                        UserInfoList += "<td>" + "男" + "</td>\n";
                    } else {
                        UserInfoList += "<td>" + "女" + "</td>\n";
                    }
                    UserInfoList +=
                        "<td>" + item.identity + "</td>\n" +
                        "<td>" + item.bankcard + "</td>\n" +
                        "<td>" + item.phone + "</td>\n" +
                        "<td>" + item.email + "</td>\n" +
                        "<td><input type='button' value='删除' class='delete' name='"+item.id+"'>" +
                        "<input type='button' value='修改' class='update' name='"+item.id+"'></td>" +
                        "</tr>";
                    $("#UserList").append(UserInfoList);
                })
                if (data.pageNum==1){
                    $("#page1").append($("<a class=\"prev\">&lt;&lt;</a>"));
                }else {
                    $("#page1").append($("<a class=\"prev\" onclick='init("+data.prePage+")'>&lt;&lt;</a>"));
                }
                for (var i=1;i<=data.lastPage;i++){
                    if (data.pageNum==i){
                        $("#page1").append($(" <span onclick='init("+i+")' class=\"current\">"+i+"</span>"))
                    }else {
                        $("#page1").append($("<a class=\"num\" onclick='init("+i+")'>"+i+"</a>"))
                    }
                }
                if (data.pageNum==data.lastPage){
                    $("#page1").append($("<a class=\"next\">&gt;&gt;</a>"));
                } else {
                    $("#page1").append($("<a class=\"next\" onclick='init("+data.nextPage+")'>&gt;&gt;</a>"));
                }
            },
            error: function (data) {
                alert(111);
                console.error(data+"******************");
            }
        })
    }
    // $("#UserList").DataTable();
    layui.use(['laydate', 'form'], function () {
        var laydate = layui.laydate;
        var form = layui.form;

        // 点击事件1
        $(document).on("click",".delete",function(){
            //1. 获取id值
            srcElement = window.event.srcElement;
            var did=srcElement.name;


            $.ajax({
                type: 'POST',
                url: "delUser",
                contentType: "application/json; charset=utf-8",
                data: JSON.stringify({
                    "id": did,

                }),
                dataType: "json",
                success: function (data) {
                    if (data) {
                        window.location.reload();
                    } else {
                        alert("删除失败")
                    }
                },
                error: function (data) {
                    console.error("111" + data);
                }
            })

        })
        $(document).on("click",".update",function () {
            srcElement = window.event.srcElement;
            var UserId=srcElement.name;
            // window.location.href="member-edit.html?id="+UserId;
            xadmin.open("编辑","member-edit.html?id="+UserId,600,400);
        })

        // 监听全选
        form.on('checkbox(checkall)', function (data) {

            if (data.elem.checked) {
                $('tbody input').prop('checked', true);
            } else {
                $('tbody input').prop('checked', false);
            }
            form.render('checkbox');
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#end' //指定元素
        });


    });

    /*用户-停用*/
    function member_stop(obj, id) {
        layer.confirm('确认要停用吗？', function (index) {

            if ($(obj).attr('title') == '启用') {

                //发异步把用户状态进行更改
                $(obj).attr('title', '停用')
                $(obj).find('i').html('&#xe62f;');

                $(obj).parents("tr").find(".td-status").find('span').addClass('layui-btn-disabled').html('已停用');
                layer.msg('已停用!', {icon: 5, time: 1000});

            } else {
                $(obj).attr('title', '启用')
                $(obj).find('i').html('&#xe601;');

                $(obj).parents("tr").find(".td-status").find('span').removeClass('layui-btn-disabled').html('已启用');
                layer.msg('已启用!', {icon: 5, time: 1000});
            }

        });
    }




    function delAll(argument) {
        //获取id
        var ids = [];
        var chec=document.getElementsByClassName("checkbox1");
        for (var i=0;i<chec.length;i++){
            if (chec[i].checked==true){
                ids.push(chec[i].id)
            }
        }
        layer.confirm('确认要删除吗？' + ids.toString(), function (index) {
            //捉到所有被选中的，发异步进行删除
            $.ajax({
                type: 'POST',
                url: "delUserByIds",
                contentType: "application/json; charset=utf-8",
                data: JSON.stringify({
                    "ids": ids,

                }),
                dataType: "json",
                success: function (data) {
                    if (data) {
                        window.location.reload();
                    } else {
                        alert("删除失败")
                    }
                },
                error: function (data) {
                    console.error("111" + data);
                }
            })

        });
    }

    function JumpToEdit(id) {
        window.location.href = "member-edit.html?id=" + id;
    }
</script>
<script type="text/javascript">

</script>
</html>